#include "Mutex.h"

WinTools::CMutex::CMutex()
{
	InitializeCriticalSection(&m_Mutex);
}

WinTools::CMutex::~CMutex()
{
	DeleteCriticalSection(&m_Mutex);
}

void WinTools::CMutex::Lock()
{
	EnterCriticalSection(&m_Mutex);
}

void WinTools::CMutex::Unlock()
{
	LeaveCriticalSection(&m_Mutex);
}

bool WinTools::CMutex::TryLock()
{
	return (TryEnterCriticalSection(&m_Mutex) == TRUE);
}

bool WinTools::CMutex::IsLocked()
{
	bool bIsLocked = (TryEnterCriticalSection(&m_Mutex) == TRUE);
	if (bIsLocked)
		LeaveCriticalSection(&m_Mutex);

	return bIsLocked;
}
